package com.example.child_protection.controller;

import com.example.child_protection.dto.base.BaseResponseDTO;
import com.example.child_protection.dto.request.SimpleIdRequestDTO;
import com.example.child_protection.dto.request.add.RoleMeunAndButtonInsertRequestDTO;
import com.example.child_protection.dto.request.add.SystemRoleMenuInsertRequestDTO;
import com.example.child_protection.dto.request.find.SystemRoleMenuRequestDTO;
import com.example.child_protection.dto.request.update.SystemRoleMenuUpdateRequestDTO;
import com.example.child_protection.dto.response.SystemRoleMenuListResponseDTO;
import com.example.child_protection.service.SystemRoleMenuManageService;
import com.example.child_protection.service.SystemRoleMenuQueryService;
import com.example.child_protection.util.ContentType;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * 角色菜单信息管理控制层
 * @date 2018-11-2
 * @author Biz
 */
@RestController
@RequestMapping("systemRoleMenu")
@Api(value = "/api-systemRoleMenu", description = "角色菜单信息管理")
public class SystemRoleMenuController extends BaseController {

    @Autowired
    public SystemRoleMenuManageService systemRoleMenuManageService;

    @Autowired
    public SystemRoleMenuQueryService systemRoleMenuQueryService;

    @ApiOperation(value ="角色菜单信息查询", httpMethod = "POST",response = BaseResponseDTO.class )
    @RequestMapping(value = "/findList", method = RequestMethod.POST, produces = {ContentType.APPLICATION_JSON_UTF_8, ContentType.TEXT_XML_UTF_8})
    public SystemRoleMenuListResponseDTO findList(SystemRoleMenuRequestDTO requestDTO)throws Exception{
        SystemRoleMenuListResponseDTO responseDTO = systemRoleMenuQueryService.findList(requestDTO);
        return responseDTO;
    }

    @ApiOperation(value ="添加角色菜单信息", httpMethod = "POST",response = BaseResponseDTO.class )
    @RequestMapping(value = "/insert", method = RequestMethod.POST, produces = {ContentType.APPLICATION_JSON_UTF_8, ContentType.TEXT_XML_UTF_8})
    public BaseResponseDTO insert(SystemRoleMenuInsertRequestDTO requestDTO)throws Exception{
        requestDTO.setCreatePersonId(this.getLoginUserId());
        requestDTO.setLastUpdatePersonId(this.getLoginUserId());
        BaseResponseDTO responseDTO = systemRoleMenuManageService.insert(requestDTO);
        return responseDTO;
    }

    @ApiOperation(value ="修改角色菜单信息", httpMethod = "POST",response = BaseResponseDTO.class )
    @RequestMapping(value = "/update", method = RequestMethod.POST, produces = {ContentType.APPLICATION_JSON_UTF_8, ContentType.TEXT_XML_UTF_8})
    public BaseResponseDTO update(SystemRoleMenuUpdateRequestDTO requestDTO)throws Exception{
        requestDTO.setCreatePersonId(this.getLoginUserId());
        requestDTO.setLastUpdatePersonId(this.getLoginUserId());
        BaseResponseDTO responseDTO = systemRoleMenuManageService.update(requestDTO);
        return responseDTO;
    }

    @ApiOperation(value ="删除角色菜单信息", httpMethod = "POST",response = BaseResponseDTO.class )
    @RequestMapping(value = "/delete", method = RequestMethod.POST, produces = {ContentType.APPLICATION_JSON_UTF_8, ContentType.TEXT_XML_UTF_8})
    public BaseResponseDTO delete(SimpleIdRequestDTO requestDTO)throws Exception{
        requestDTO.setCreatePersonId(this.getLoginUserId());
        requestDTO.setLastUpdatePersonId(this.getLoginUserId());
        BaseResponseDTO responseDTO = systemRoleMenuManageService.delete(requestDTO);
        return responseDTO;
    }

    @ApiOperation(value ="保存角色权限", httpMethod = "POST",response = BaseResponseDTO.class )
    @RequestMapping(value = "/insertRoleMenuAndButton", method = RequestMethod.POST, produces = {ContentType.APPLICATION_JSON_UTF_8, ContentType.TEXT_XML_UTF_8})
    public BaseResponseDTO insertRoleMenuAndButton(RoleMeunAndButtonInsertRequestDTO requestDTO)throws Exception{
        requestDTO.setCreatePersonId(this.getLoginUserId());
        requestDTO.setLastUpdatePersonId(this.getLoginUserId());
        BaseResponseDTO responseDTO = systemRoleMenuManageService.insertRoleMenuAndButton(requestDTO);
        return responseDTO;
    }

}
